package com.tommy.ddp.swapHandle
{
	import com.tommy.ddp.box.DdpBox;
	import com.tommy.ddp.manager.FillUpManager;
	import com.tommy.ddp.manager.Finder;
	
	import flash.utils.setTimeout;

	/**
	 * 最普通的交换以后查找\消除
	 * @author hongxuan
	 * 
	 */	
	public class NormalSwapHandler// implements ISwapHandler
	{
		private var finderVect:Vector.<Finder>;
		
		protected var columnList:Vector.<int>;
		
		public function NormalSwapHandler()
		{
			finderVect = new Vector.<Finder>();
			columnList = new Vector.<int>();
			columnList.push(0,1,2,3,4,5,6,7,8);
		}
		
		public function execute(vect:Vector.<DdpBox>):void
		{
			for each(var i:DdpBox in vect)
			{
				var finder:Finder = new Finder();
				finder.start(i);
				//为finder创建一个按X\Y排序的标志位，用以去重（有可能两个棋子寻出来的内容一样）
				finderVect.push(finder);
			}
			
			getAllColumnList();
			
			for each(var j:Finder in finderVect)
			{
				j.dispose();
			}
			//
			
			setTimeout(function():void
			{
				//|||FillUpManager.fillUp(columnList);
			},1000);
		}
		
		/**
		 * 获取所有被消除的棋子的列集合
		 * @return 
		 * 
		 */		
		protected function getAllColumnList():Vector.<int>
		{
			columnList = new Vector.<int>();
			
			for each(var i:Finder in finderVect)
			{
				var v:Vector.<int> = i.columnList;
				for each(var j:int in v)
				{
					if(columnList.indexOf(j) == -1)
						columnList.push(j);
				}
			}
			
			return columnList;
		}
		
		public function dispose():void
		{
			finderVect = null;
		}
	}
}